<template>
    <div class="search-bar">
        <div class="btn-list">
            <div class="arrow-left"></div>
            <div class="btn-item" :class="{ active: btnActiveClass == item.id }" 
            v-for="item in categoryList" :key="item.id" 
            @click="searchBar(item.id, item)">{{ item.value }}</div>
            <div class="arrow-right"></div>
        </div>
    </div>
</template>

<script>
export default {
    components: {},
    data() {
        return {
            btnActiveClass: 0,
        };
    },
    props: {
        // 分类列表
        categoryList: {
            type: Array,
            default: [],
        },
    },
    watch: {},
    mounted() {
        // 确保进入页面查询
        // this.searchBar(0, this.categoryList[0]);
        console.log(this.categoryList,'categoryList')
    },
    methods: {
        // 搜索
        searchBar(i, item) {
            this.btnActiveClass = i;
            this.$emit("categoryBar", item);
        },
    },
};
</script>
<style scoped lang="scss">
@import "~@/styles/variables.scss";
.search-bar {
    width: 100%;
    height: $searchBarHeight;
    background-color: #f8f8f8;
    display: flex;
    align-items: center;
    margin: 10px 0;
    .btn-list {
        position: relative;
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        .btn-item {
            /* width: 145px; */
            height: 80%;
            margin-right: 5px;
            padding: 0px 40px;
            font-size: 16px;
            border: 1px solid #59a1e8;
            background-color: transparent;
            color: #59a1e8;
            text-align: center;
            line-height: 40px;
            cursor: pointer;
            &:hover {
                background-color: #397dc1;
                color: #fff;
            }
            &.active {
                background-color: #397dc1;
                color: #fff;
            }
        }
        .arrow-left {
            position: relative;
            width: 20px;
            height: 80%;
            background-color: rgba(4, 128, 251, 0.3);
            margin-right: 5px;
            &::before {
                content: "";
                position: absolute;
                top: 5px;
                left: -10px;
                width: 0px;
                height: 0px;
                border: 15px solid transparent;
                border-right: 10px solid #0480fb;
            }
        }
        .arrow-right {
            position: absolute;
            right: 0;
            width: 20px;
            height: 80%;
            background-color: rgba(4, 128, 251, 0.3);
            &::before {
                content: "";
                position: absolute;
                top: 5px;
                left: 5px;
                width: 0px;
                height: 0px;
                border: 15px solid transparent;
                border-left: 10px solid #0480fb;
            }
        }
    }
}
</style>
